/*
This is an example script for a 2D cubic bezier graphic. Click the Execute button to apply and then execute this script. Upon each execution the cubic bezier alters its appearance. Turn on animation to execute periodically. Note that typically a cubic bezier graphic should be instantiated on a graph data layer and the graph should be set to autoscale during animation.
*/

/* Declarations */

double cos(double a);
double sin(double a);

@@class() CubicBezier:Object

@@method(public, class) (id)stored;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;

@@end

/* Execution block */

{
id myCubicBezier;
int ii;
double xValue, yValue, radius, center, phase;
unsigned animationCount;
double red, green, blue;

myCubicBezier = [CubicBezier stored];

animationCount = [myCubicBezier animationCount];

/*
Empty the data and then append new data.
*/

[myCubicBezier emptyData];

center = 4.0;
phase = animationCount * 0.1;

for(ii = 0; ii < 40; ii++)
{

radius = ii * 0.1;

red = 1.0;
green = (animationCount % 30) / 30.0;
blue = 1.0;
xValue = radius * cos(ii * .3 + phase) + center;
yValue = radius * sin(ii * .3 + phase) + center;

[myCubicBezier appendXValue:xValue yValue:yValue];
}

}
